import { Alova, AlovaInstance } from '@/utils/http/alova/index';

export interface UserInfo {
  username: string;
  password: string;
}

/**
 * @description: 获取用户信息
 */
// export function getUserInfo() {
//   return Alova.Get<InResult>('/admin_info', {
//     meta: {
//       isReturnNativeResponse: true,
//     },
//   });
// }
export function getUserInfo() {
  return AlovaInstance.Post<InResult>('/admin_info', {
    method: 'login',
    login: `admin:admin`,
  });
}

/**
 * @description: 用户登录
 */
// export function login(params) {
//   return Alova.Post<InResult>(
//     '/login',
//     {
//       params,
//     },
//     {
//       meta: {
//         isReturnNativeResponse: true,
//       },
//     }
//   );
// }
export function login(params: UserInfo) {
  return AlovaInstance.Post<InResult>(
    '',
    {
      method: 'login',
      login: `${params.username}:${params.password}`,
    },
    {
      headers: { 'Content-Type': 'application/json' },
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return Alova.Post(`/user/u${uid}/changepw`, { params });
}

/**
 * @description: 用户登出
 */
export function logout(params) {
  return Alova.Post('/login/logout', {
    params,
  });
}
